Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Pick random map from list and set results as cvar

  1. #1

    Default Pick random map from list and set results as cvar

    Ultimately I'd like to add a "random next map" button to my RCON tool that will pick a custom map from our list of 300 maps and set it for the next map. So basically, rcon randmapGO 1 would trigger the script, it would do its thing, then rcon randmapGO would return to 0. I'm not sure if I'm even on the right track with this script, but this is what I've been trying.. It's not working, so I'm looking for some help from the community. Let me know if there are any suggestions or if this is not something that can be done with Mohaa.

    Thanks guys,



    main:
    
    "setcvar" "randmapGO" "0"
    
    	whlie(1)
    	{
    		if(getcvar(randmapGO)==1)
    		{
    			local.map[1] = (dm/mohdm1)
    			local.map[2] = (dm/mohdm2)
    			local.map[3] = (dm/mohdm3)
    			local.map[4] = (dm/mohdm4)
    			local.map[5] = (dm/mohdm5)
    			local.map[6] = (dm/mohdm6)
    			local.map[7] = (dm/mohdm7)
    			local.map[8] = (obj/obj_team1)
    
    				while(1)
    				{
    					local.randmap = local.map[((randomint local.map.size) + 1)]
    				}
    
    			setcvar "nextmap" local.randmap
    
    			"setcvar" "randmapGO" "0"
    		}
    	wait 3
    	}
    end

  2. #2

    Default

    On your script you have some problems.

    1 - On the line 7 you not checking a string on the variable because your not puting the " between the 1.

    Only do this way if you have number in a variable like this local.number = 1.

    2 - Between the line 9 and 16 you are not puting the map names as a string, you puting like a vector.

    To be a string as to be with the ".

    3 - On the line 18 you dont need a infinite loop to set the map, you can set only with one time.

    4 - On the line 3 and 25 setcvar is whitout " like this setcvar "randmapGO" "0".
    Last edited by DoubleKill; December 15th, 2016 at 09:59 AM.

  3. #3

    Default

    Thanks for the pointers, DK. I've done all those things and tested it out, but I think I'm still missing something. I'm loading the script through dmprecache (and there are no conflicting dmprecache files) but still when I type rcon randmapGO into console, it doesn't return anything (normally, I would expect to see something like randmapGO is "0" default is "1" or something).

    Do you have any other ideas? :/


    main:
    
    local.randmapdisplay = ""
    local.randmapgo = 0
    setcvar "randmapgo" "0"
    
    	whlie(1)
    	{
    		local.randmapgo = getcvar "randmapgo"
    		if(local.randmapgo == 1)
    		{
    
    			local.map[1] = "dm/mohdm1"
    			local.map[2] = "dm/mohdm2"
    			local.map[3] = "dm/mohdm3"
    			local.map[4] = "dm/mohdm4"
    			local.map[5] = "dm/mohdm5"
    			local.map[6] = "dm/mohdm6"
    			local.map[7] = "dm/mohdm7"
    			local.map[8] = "obj/obj_team1"
    
    			local.randmapdisplay = local.map[((randomint local.map.size) + 1)]
    
    			setcvar "nextmap" local.randmapdisplay
    			//wait 1
    			//setcvar "randmapgo" "0"
    		}
    	wait 3
    	}
    end


    Question:

    --is it better to have a code that looks like lines 9/10 on the second post, or line 7 on the first post?
    setting a cvar to a local.something and checking off that, or just checking off the cvar?
    Last edited by [cB]SplatterGuts; December 15th, 2016 at 03:59 PM.

  4. #4

    Default

    You only have forgot to put the 1 between the " lol.

    I have put the variable to reset on the loop or will keep setting the map every time.

    Maybe i have explaing wrong about to check the variable.

    When you whant to check a value from a variable from the game you can change, that variable value is considered a string.

    To check a string you have to use like this local.randmapgo == "1".

    But for a internal variable from the game, for example to check the player if is pressing the use key you have to use like this local.player.useheld == 1.

    Or for a variable you have created and if you convert the variable value from a string to int like this int(local.randmapgo) == 1.

    main:
    
    local.randmapdisplay = ""
    local.randmapgo = 0
    
    	while(1)
    	{
    		local.randmapgo = getcvar "randmapgo"
    
    		if(local.randmapgo == "1")
    		{
    
    			local.map[1] = "dm/mohdm1"
    			local.map[2] = "dm/mohdm2"
    			local.map[3] = "dm/mohdm3"
    			local.map[4] = "dm/mohdm4"
    			local.map[5] = "dm/mohdm5"
    			local.map[6] = "dm/mohdm6"
    			local.map[7] = "dm/mohdm7"
    			local.map[8] = "obj/obj_team1"
    
    			local.randmapdisplay = local.map[((randomint local.map.size) + 1)]
    
    			setcvar "nextmap" local.randmapdisplay
    			setcvar "randmapgo" "0"
    
    		}
    	wait 3
    	}
    end
    Last edited by DoubleKill; December 16th, 2016 at 05:40 AM.

  5. #5

    Default

    Quote Originally Posted by DoubleKill View Post
    When you whant to check a value from a variable from the game you can change, that variable value is considered a string.

    To check a string you have to use like this local.randmapgo == "1".

    But for a internal variable from the game, for example to check the player if is pressing the use key you have to use like this local.player.useheld == 1.

    Or for a variable you have created and if you convert the variable value from a string to int like this int(local.randmapgo) == 1.

    That makes so much sense now! Thank you, I was confused by the first post a bit :P

    You're the bomb, DK! This works, now just to add the hundreds of custom maps on the server to the list lol

  6. #6
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,566

    Default

    I still don't understand why don't you use scmd instead of the old cvars and while loops :3

  7. #7

    Default

    How would i do that, ryback? I used scmd for my RCON tool to set the map and nextmap and do a few admin controls. Just let me know what an example would look like for this.

  8. #8

    Default

    here is a simple code i made
    using flist function will save you the time from adding the maps one by one to the list, instead it will get all the maps you have in your server in only one line of code.

    the only extra thing you will need to download in order to get it to work is the Sor's Scripting Framework zzzzzzzzzzzzz_ScriptFramework_0822BETA.pk3 (http://www.x-null.net/forums/showthr...p/1794-Updates). (this works using the reborn_loader so it won't cause any conflict with your mods)

    randmap:
        local.maplist = flist "maps/" ".bsp" 1;    // get all .bsp files from maps folder
    
        while(1) {
            local.randmap = local.maplist[randomint(local.maplist.size)];    // pick a random map
            local.randmap = waitthread game.System.String.SubStr local.randmap 0 (local.randmap.size - 4);    // remove '.bsp' from the string
    
            // check for avoid to pick a sp map
            local.check = waitthread game.System.String.Split local.randmap "\/";
            if (local.check[1] == "dm" || local.check[1] == "obj") {
                break;
            }
        }
    
        stuffsrv("say next map: " + local.randmap + "\n");
        setcvar "nextmap" local.randmap;
    end;


    you can call the randmap thread using the rcon or scmd method, whatever you find easier
    If you have any questions just ask

  9. #9

    Default

    Oh wow, that's really cool. I didn't know flist was a thing. Thank you!

  10. #10

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •